package com.wangsd.web.utils;

import java.util.HashMap;

/**
 * 数据封装
 */
public class R extends HashMap<String, Object> {

    public R() {
    }

    public R put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public static R success() {
        R r = new R();
        r.put("code", 200);
        r.put("msg", "success");
        return r;
    }

    public static R success(String msg) {
        return success().put("msg", msg);
    }

    public R data(Object data) {
        this.put("data", data);
        return this;
    }

    public static R error(String msg) {
        return R.error(500, msg);
    }

    public static R error(int code, String msg) {
        R result = new R();
        result.put("code", code).put("msg", msg);
        return result;
    }
}